Imports System.ComponentModel

Public Class UnitConfigurationCollection
   Inherits CollectionBase
   Implements ICustomTypeDescriptor

#Region "Public Properties"

   Default Public ReadOnly Property Item(ByVal iIndex As Integer) As UnitConfiguration
      Get
         Return DirectCast(Me.List(iIndex), UnitConfiguration)
      End Get
   End Property

#End Region

#Region "Public Methods"

   Public Sub Add(ByVal iUnitConfig As UnitConfiguration)
      Me.List.Add(iUnitConfig)
   End Sub

   Public Sub Remove(ByVal iUnitConfig As UnitConfiguration)
      Me.List.Remove(iUnitConfig)
   End Sub

   Public Overrides Function ToString() As String
      Return "(Collection)"
   End Function

#Region "ICustomTypeDescriptor Implementation"

   Public Function GetClassName() As String Implements System.ComponentModel.ICustomTypeDescriptor.GetClassName
      Return TypeDescriptor.GetClassName(Me, True)
   End Function

   Public Function GetAttributes() As AttributeCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetAttributes
      Return TypeDescriptor.GetAttributes(Me, True)
   End Function

   Public Function GetComponentName() As String Implements System.ComponentModel.ICustomTypeDescriptor.GetComponentName
      Return TypeDescriptor.GetComponentName(Me, True)
   End Function

   Public Function GetConverter() As TypeConverter Implements System.ComponentModel.ICustomTypeDescriptor.GetConverter
      Return TypeDescriptor.GetConverter(Me, True)
   End Function

   Public Function GetDefaultEvent() As EventDescriptor Implements System.ComponentModel.ICustomTypeDescriptor.GetDefaultEvent
      Return TypeDescriptor.GetDefaultEvent(Me, True)
   End Function

   Public Function GetDefaultProperty() As PropertyDescriptor Implements System.ComponentModel.ICustomTypeDescriptor.GetDefaultProperty
      Return TypeDescriptor.GetDefaultProperty(Me, True)
   End Function

   Public Function GetEditor(ByVal iEditorBaseType As Type) As Object Implements System.ComponentModel.ICustomTypeDescriptor.GetEditor
      Return TypeDescriptor.GetEditor(Me, iEditorBaseType, True)
   End Function

   Public Function GetEvents(ByVal iAttributes As Attribute()) As EventDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetEvents
      Return TypeDescriptor.GetEvents(Me, iAttributes, True)
   End Function

   Public Function GetEvents() As EventDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetEvents
      Return TypeDescriptor.GetEvents(Me, True)
   End Function

   Public Function GetPropertyOwner(ByVal iPd As PropertyDescriptor) As Object Implements System.ComponentModel.ICustomTypeDescriptor.GetPropertyOwner
      Return Me
   End Function

   Public Function GetProperties(ByVal iAttributes As Attribute()) As PropertyDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetProperties
      Return GetProperties()
   End Function

   Public Function GetProperties() As PropertyDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetProperties
      ' Create a collection object to hold property descriptors
      Dim propertyDescriptors As PropertyDescriptorCollection
      Dim propertyDescriptor As UnitCollectionPropertyDescriptor

      propertyDescriptors = New PropertyDescriptorCollection(Nothing)
      ' Iterate the list of employees
      For i As Integer = 0 To Me.List.Count - 1
         ' Create a property descriptor for the item and add to the property descriptor collection
         propertyDescriptor = New UnitCollectionPropertyDescriptor(Me(i))
         propertyDescriptors.Add(propertyDescriptor)
      Next
      ' return the property descriptor collection
      Return propertyDescriptors
   End Function

#End Region

#End Region

End Class
